import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../pages/user_releases_tab.dart';
import '../pages/user_favorites_tab.dart';

class ProfileTabSection extends StatefulWidget {
  final TabController tabController;

  const ProfileTabSection({super.key, required this.tabController});

  @override
  State<ProfileTabSection> createState() => _ProfileTabSectionState();
}

class _ProfileTabSectionState extends State<ProfileTabSection> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        _buildTabBar(),

        SizedBox(
          height: MediaQuery.of(context).size.height * 0.6,
          child: TabBarView(
            controller: widget.tabController,
            children: const [UserReleasesTab(), UserFavoritesTab()],
          ),
        ),
      ],
    );
  }

  Widget _buildTabBar() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 40.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          _buildTabItem('My Release', 0),
          _buildTabItem('My Likes', 1),
        ],
      ),
    );
  }

  Widget _buildTabItem(String title, int index) {
    return GestureDetector(
      onTap: () {
        widget.tabController.animateTo(index);
        setState(() {});
      },
      child: AnimatedBuilder(
        animation: widget.tabController,
        builder: (context, child) {
          final isSelected = widget.tabController.index == index;

          return Column(
            children: [
              Text(
                title,
                style: TextStyle(
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w600,
                  color:
                      isSelected
                          ? Colors.white
                          : Colors.white.withValues(alpha: 0.6),
                  fontFamily: 'Poppins',
                ),
              ),

              SizedBox(height: 8.h),

              // 选中指示点
              Container(
                width: 6.w,
                height: 6.w,
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  color: isSelected ? Colors.white : Colors.transparent,
                ),
              ),
            ],
          );
        },
      ),
    );
  }
}
